package se.peterbjorkman.android.trafikkamera.infodownload;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class CameraJsonParser {

	public void parseCameraJson(JSONObject obj, ParserCallback callback) throws JSONException{
		JSONArray array = obj.getJSONArray("cameras");
		int numberOfCameras = array.length();
		for (int i = 0; i < numberOfCameras; i++) {
			JSONObject camera  = array.getJSONObject(i);
			String id          = camera.getString("id");
			String name        = camera.getString("name");
			String description = camera.getString("description");
			String road        = camera.optString("road",null);
			int county         = camera.optInt("county", 0);
			double longitude   = camera.optDouble("longitude", 0);
			double latitude    = camera.optDouble("latitude", 0);
			String url         = camera.getString("url");
			String handheldUrl = camera.optString("handheldurl", null);
			callback.HandleCamera(id, name, description, road, county, longitude, latitude, url, handheldUrl);
			callback.SetParseProgress(i + 1, numberOfCameras);
		}
	}
}
